import Vue from 'vue'
import VueRouter from 'vue-router'
import Index from '../views/Index.vue'

Vue.use(VueRouter)

const routes = [{
		path: '/',
		name: 'Index',
		component: Index,
		children: [{
			path: '/',
			name: 'NewList',
			component: () => import('../views/Index/NewList.vue'),
			meta: {
				title: "最新列表页"
			}
		}, {
			path: '/hotList',
			name: 'HotList',
			component: () => import('../views/Index/HotList.vue'),
			meta: {
				title: "热搜列表页"
			}
		}]
	},
	{
		path: '/issue',
		name: 'Issue',
		component: () => import('../views/Issue.vue'),
		meta: {
			title: "发布博客页",
			isCheck:true
		}
	},
	{
		path: '/user/:userName',
		name: 'User',
		component: () => import('../views/User.vue'),
		meta: {
			title: "用户中心页",
			isCheck:false
		}
	},
	{
		path: '/index',
		redirect: '/'
	},
	{
		path: '/home',
		redirect: '/'
	},
	{
		path: '*',
		redirect: '/'
	}
]

const router = new VueRouter({
	routes
})

router.beforeEach((to, from, next) => {
	document.title = to.meta.title
	if (to.path == "/Issue") {
		if (!localStorage.getItem('isLogin')) {
			next('/user/123');
		}
	}
	next();
})


export default router
